package com.song.article.stream;

import com.song.pojo.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * 开启绑定器
 * 绑定通道channel
 */
@Component
@EnableBinding(MyStreamChannel.class)
public class StreamServiceImpl implements StreamService {

    // 注入管道output，用于发送消息
    @Autowired
    private MyStreamChannel myStreamChannel;

    @Override
    public void sendStream() {
        AppUser user = new AppUser();
        user.setId("test1001");
        user.setNickname("song");

        // 发送消息
        myStreamChannel.output().send(MessageBuilder.withPayload(user).build());
    }
}

